package middle_class;

import java.util.Arrays;

public class Code01_MaxPoint {

    public static int getMaxPoint(int[] nums, int k) {
        int n = nums.length;
        int[] res = new int[n];
        Arrays.fill(res, 1);
        for (int i = 0; i < n; i++) {
            int value = nums[i] - k;
        }
        return 1;
    }

    // 0~R 范围上 >= value 最左的数坐标
    public static int nearestLeftIndex(int[] nums, int R, int value) {
        int L = 0;
        while (L < R) {
            int mid = L + ((R - L) >> 1);
            if (nums[mid] == value) {
                return mid;
            } else if (nums[mid] > value) {
                R--;
            } else if (nums[mid] < value) {
                L++;
            }
        }
        return -1;
    }


    public static int getMaxPoint2(int[] nums, int k) {

        int right = 0;
        int[] res = new int[nums.length];
        for (int left = 0; left < nums.length; left++) {
            res[left] = right - left;
            while (right < nums.length && nums[right] - nums[left] <=5) {
                res[left]++;
                right++;
            }
            right--;
        }
        Arrays.sort(res);
        return res[nums.length - 1];
    }

    public static void main(String[] args) {
        int[] nums = { 0, 13, 24, 35, 46, 57, 60, 72, 87 };
        System.out.println(getMaxPoint2(nums, 2));
    }
}
